<template>
  <div :key="mkey">
    <component
      :is="mkey+'-'+name"
      v-for="name in modalMap[mkey]"
      :key="name"
    />
  </div>
</template>
<script>
import Vue from 'vue'
import BModal from 'BModal'

/*
    增加服务的接口
  * */
BModal.modalMap = {
  header: [],
  footer: []
}
BModal.addModalComponent = function (model, mkey) {
  if (!BModal.modalMap[mkey]) { BModal.modalMap[mkey] = [] }

  if (BModal.modalMap[mkey].indexOf(model.name) === -1) {
    BModal.modalMap[mkey].push(model.name)
    Vue.component(mkey + '-' + model.name, model)
  }
}

export default {
  name: 'Modal',

  props: ['mkey'],
  data: function () {
    if (!BModal.modalMap[this.mkey]) {
      BModal.modalMap[this.mkey] = []
    }
    return {
      modalMap: BModal.modalMap
    }
  }
}
</script>
